/**
 * Copyright 2013 - Les petits mots
 */
function getVolumeFromStorage(){
	var volumeStorage = window.localStorage.getItem("volume");
	if(volumeStorage != null) return volumeStorage;
	return 75;
}

function saveVolume(){
	window.localStorage.setItem("volume", VOLUME);
}

function getItemProgression() {
	return window.localStorage.getItem(chosenGame + "." + chosenLevel + "." + chosenWord);
}

function getItemProgressionById(game,level,word) {
	return window.localStorage.getItem(game + "." + level + "." + word);
}

function gameComplete(){
	window.localStorage.setItem(chosenGame + "." + chosenLevel + "." + chosenWord, true);
}

function puzzleComplete(){
	//On sauvegarde la réussite du niveau
	window.localStorage.setItem(chosenGame + "." + chosenLevel + "." + chosenWord, true);
	
	//Pour les difficultés 2 et 3 on sauvegarde le nombre de coups
	if (chosenLevel == LEVEL_2 || chosenLevel == LEVEL_3) {
		if(numberHitsReccord == null || numberHitsReccord == 0 || numberHitsCurrent < numberHitsReccord) {
			window.localStorage.setItem(chosenGame + "." + chosenLevel + "." + chosenWord + ".coup", numberHitsCurrent);
		}
	}

	//Pour la difficulté 3 on sauvegarde le temps écoulé également
	if (chosenLevel == LEVEL_3) {
		//On convertie le temps passé et le temps record en secondes pour comparer
		var minutes_passed = timeSpentCurrent.getMinutes();
	    var seconds_passed = timeSpentCurrent.getSeconds();
	    var totalTime = parseInt(minutes_passed) * 60 + parseInt(seconds_passed);
	    
	    if(timeSpentReccord != null && timeSpentReccord != 0) {
		    var tmp = Array();
		    tmp = timeSpentReccord.split(":");
		    timeSpentReccord = parseInt(tmp[0]) * 60 +  parseInt(tmp[1]);
	    } else {
	    	timeSpentReccord = 0;
	    }
	    
	    //Si le temps est inférieur au record, on met en forme et on sauvegarde 
	    if(timeSpentReccord == null || timeSpentReccord == 0 || totalTime < timeSpentReccord) {
		    if(minutes_passed < 10){
		        minutes_passed = "0" + minutes_passed;
		    }
		    if(seconds_passed < 10){
		        seconds_passed = "0" + seconds_passed;
		    }
		    
		    var temps = minutes_passed + ":" + seconds_passed;
		    
			window.localStorage.setItem(chosenGame + "." + chosenLevel + "." + chosenWord + ".temps", temps);
	    }
	}
}

function getPuzzleReccordNumHits () {
	return window.localStorage.getItem(chosenGame + "." + chosenLevel + "." + chosenWord + ".coup");
}

function getPuzzleReccordTime() {
	return window.localStorage.getItem(chosenGame + "." + chosenLevel + "." + chosenWord + ".temps");
}

function resetProgression(){
	window.localStorage.clear();
	saveVolume();
};